package com.enqualcomm.kids.component.command;

import android.content.Context;

import com.android.volley.VolleyError;
import com.android.volley.socket.SocketClient;
import com.android.volley.socket.SocketNetwork;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.BasicParams;
import com.enqualcomm.kids.network.socket.response.BasicResult;


import common.utils.NetUtil;
/**
 * Created by yinzhiqun on 2015/10/16.
 *
 */
public class SendCommand implements BaseCommand {

    private final BasicParams params;
    private final SocketNetwork socketNetwork;
    private Context context;

    public SendCommand(Context context,BasicParams params){
        this.params = params;
        this.context = context;
        socketNetwork = SocketClient.initSocketNetwork(context);
    }

    @Override
    public int execute() {
        if (NetUtil.checkNet(context)){
            try {
                socketNetwork.performRequest(new SocketRequest<BasicResult>(params, null));
            } catch (VolleyError volleyError) {
                return NO_CONNECTION;
            }catch (Exception e) {
                return ERROR;
            }
            return STATUS_OK;
        }else{
            return NO_CONNECTION;
        }
    }
}
